<?php
class ControllerModuleTreodenFeaturedCategories extends Controller {
	protected function index($setting) {
		$this->language->load('module/treoden_featuredcategories'); 

      	$this->data['heading_title'] = $this->language->get('heading_title');
			
		$this->load->model('catalog/category'); 
		
		$this->load->model('tool/image');

		$this->data['categories'] = array();

		$categories = $this->config->get('treoden_featuredcategories');
		foreach($categories as $category_id){
			$category_info = $this->model_catalog_category->getCategory($category_id);
			 if ($category_info){
				if ($category_info['image']) {
					$image = $this->model_tool_image->resize($category_info['image'], $setting['image_width'], $setting['image_height'], 'h');
				} else {
					$image = false;
				}
				$this->data['categories'][] = array(
					'category_id' => $category_info['category_id'],
					'thumb'   	 => $image,
					'name'    	 => $category_info['name'],
					'href'    	 => $this->url->link('product/category', 'path=' . $category_info['category_id']),
					'description'=> utf8_substr(strip_tags(html_entity_decode($category_info['description'], ENT_QUOTES, 'UTF-8')), 0, 80) . '...'
				);
			 }
		}
		$this->data['columns'] = $setting['columns'];
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/treoden_featuredcategories.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/module/treoden_featuredcategories.tpl';
		} else {
			$this->template = 'default/template/module/treoden_featuredcategories.tpl';
		}

		$this->render();
	}
}
?>